package com.pay.game.central.web.service;

import com.pay.game.central.web.bean.TelegramBill;
import com.pay.game.central.web.bean.TelegramCard;
import com.pay.game.central.web.bean.TelegramGroup;
import com.pay.game.central.web.mapper.BotMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class BotService {

    @Autowired private BotMapper botMapper;


    public void addTelegramGroup(TelegramGroup telegramGroup){
        botMapper.addTelegramGroup(telegramGroup);
    }

    public void deleteTelegramGroup(String id){
        botMapper.deleteTelegramGroup(id);
        botMapper.removeTelegramCardGroup(id);
    }

    public List<TelegramGroup> listGroup(){
        return botMapper.listGroup();
    }

    public void addTelegramBill(TelegramBill bill){
        botMapper.addTelegramBill(bill);
    }

    public List<TelegramBill> listTelegramBill(){
        return botMapper.listTelegramBill();
    }

    public void addTelegramCard(TelegramCard telegramCard){
        botMapper.addTelegramCard(telegramCard);
    }

    public List<TelegramCard> listTelegramCard(){
        return botMapper.listTelegramCard();
    }

    public void unbindCard(String id){
        botMapper.unbindCard(id);
    }

    /**
     *
     * @param realName 持卡人姓名
     * @return -1 找不到卡，0 卡已经禁用，1 卡已经绑定， 2 卡未绑定, 3 绑定设备相匹配
     */
    public int isCardBind(String realName, String deviceId){
        TelegramCard card = botMapper.getCardInfo(realName);
        int status = card.getStatus();
        if (card == null) return -1;
        if (status == -1) return 0;
        if (status == 0 ) return 2;
        if (card.getDeviceId().equals(deviceId)) return 3;
        return 1;
    }

    public TelegramCard getCardInfo(String realName){
        return botMapper.getCardInfo(realName);
    }

    public void bindCard(String realName, String deviceId){
        botMapper.bindCard(realName, deviceId);
    }

    public void disableCard(String id){
        botMapper.unbindCard(id);
        botMapper.disableCard(id);
    }

}
